package com.rxh.controller;

import com.rxh.pojo.cross.BankResult;
import com.rxh.pojo.payment.Trade;
import com.rxh.trade.AcquirerInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class TradeController {

    @Autowired
    private List<AcquirerInterface> acquirerInterfaces;

    @RequestMapping("/trade")
    public BankResult trade(@RequestBody Trade trade) {
        for (AcquirerInterface a :
                acquirerInterfaces) {
            if (a.getAcquirerId().equals(trade.getCoreAcquirer().getId())) {
                return a.trade(trade);
            }
        }
        return null;
    }
}